﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.User.Identity.IsAuthenticated)
            Response.Redirect("index.aspx");
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            Roles.CreateRole("超级管理员");
        }
        catch { }
        try
        {
            Roles.CreateRole("班级管理员");
        }
        catch { }

        try
        {
            Membership.CreateUser(TextBox1.Text, TextBox2.Text, TextBox3.Text);
            if (Membership.ValidateUser(TextBox1.Text, TextBox2.Text))
            {
                FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
                if (TextBox1.Text.Trim().ToLower() == "admin")
                {
                    Roles.AddUserToRole(TextBox1.Text, "超级管理员");
                }




            }
        }
        catch (MembershipCreateUserException ex)
        {
            Label1.Text = ex.Message;
            
            return;
        }





        Response.Redirect("index.aspx");
      
    }

}